home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / rexx / EqFiles.lha / EqFiles.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-10-11  |  6.6 KB  |  227 lines

  1. /* $VER: EqFiles.rexx 1.8 (11.10.98)
  2. */
  3.  
  4.  
  5. /* Filenames of external programs */
  6. /*
  7. cmp='HD0:OTHER/C/Cmp'
  8. */
  9. /* If the routine does not find external program(s), uncomment the above and insert your path(s) */
  10.  
  11.  
  12. /* Parsing routine */
  13. parse upper arg template
  14. occ1=pos('"',template)
  15. if occ1=0 then parse var template dir1 dir2 opt1 opt2 .
  16. else do
  17.    occ2=pos('"',template,occ1+1)
  18.    if occ2=0 then signal error1
  19.    else do
  20.       occ3=pos('"',template,occ2+1)
  21.       select
  22.          when occ3=0 & occ1=1 then do
  23.             parse var template '"'dir1'"' dir2 opt1 opt2 .
  24.             end
  25.          when occ1~=1 then do
  26.             parse var template dir1 '"'dir2'"' opt1 opt2 .
  27.             dir1=trim(dir1)
  28.             if dir2=='' then dir2='""'
  29.             end
  30.          otherwise do
  31.             occ4=pos('"',template,occ3+1)
  32.             if occ4=0 then signal error1
  33.             parse var template '"'dir1'"' try '"'dir2'"' opt1 opt2 .
  34.             if try~='' then signal error2
  35.             if dir2=='' then dir2='""'
  36.             end
  37.          end
  38.       end
  39.    end
  40. select
  41.    when dir1='?' then signal template
  42.    when dir1=':' ^ dir1='/' ^ dir2=':' ^ dir2='/' then signal error3
  43.    when dir1='""' ^ dir1=='' then dir1=pragma('D')
  44.    when left(dir1,1)='"' & right(dir1,1)='"' then dir1=substr(dir1,2,length(dir1)-2)
  45.    when exists(dir1)=0 then signal error4
  46.    when open('test',dir1,'read')=1 then signal error5
  47.    otherwise nop
  48.    end
  49. olddir=pragma('D',dir1)
  50. dir1=pragma('D',pragma('D',dir1))
  51. if right(dir1,1)~=":" & right(dir1,1)~="/" then dir1=dir1||"/"
  52. call pragma('D',olddir)
  53. select
  54.    when dir2='DELETE' ^ dir2='ALL' then do
  55.       opt2=opt1
  56.       opt1=dir2
  57.       dir2=dir1
  58.       end
  59.    when dir2=='' then dir2=dir1
  60.    when dir2='""' then dir2=olddir
  61.    when left(dir2,1)='"' & right(dir2,1)='"' then dir2=substr(dir2,2,length(dir2)-2)
  62.    when exists(dir2)=0 then signal error6
  63.    when open('test',dir2,'read')=1 then signal error7
  64.    otherwise nop
  65.    end
  66. call pragma('D',dir2)
  67. dir2=pragma('D',pragma('D',dir2))
  68. if right(dir2,1)~=":" & right(dir2,1)~="/" then dir2=dir2||"/"
  69. diff=compare(dir1,dir2)-1
  70. if opt1~='' & opt1~='DELETE' & opt1~='ALL' then signal error8
  71. if opt2~='' & opt2~='DELETE' & opt2~='ALL' then signal error9
  72. if opt1=opt2 then opt2=''
  73.  
  74.  
  75. /* Main program */
  76. address command
  77. if dir1=dir2 then do
  78.    if opt1='' & opt2='' then say '   Scanning directory  "'dir1'"'
  79.       else say '   Scanning directory  "'dir1'"  with option(s) 'opt1 opt2''
  80.    if opt1='ALL' | opt2='ALL' then do
  81.       'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files All'
  82.       end
  83.    else do
  84.       'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files'
  85.       end
  86.    call open('in1','T:FileList1','read')
  87.    line1=readln('in1')
  88.    errdir=dir1
  89.    if EOF('in1') then signal error10
  90.    call close('in1')
  91.    'Sort T:FileList1 To T:FileList1 Case ColStart 10'
  92.    'Copy T:FileList1 To T:FileList2'
  93.    end
  94. else do
  95.    if opt1='' & opt2='' then say '   Scanning directories  "'dir1'"  and  "'dir2'"'
  96.       else say '   Scanning directories  "'dir1'"  and  "'dir2'"  with option(s) 'opt1 opt2''
  97.    if opt1='ALL' | opt2='ALL' then do
  98.       'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files All'
  99.       'List >T:FileList2 "'dir2'" lformat="%8l %p%-s" Files All'
  100.       end
  101.    else do
  102.       'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files'
  103.       'List >T:FileList2 "'dir2'" lformat="%8l %p%-s" Files'
  104.       end
  105.    call open('in1','T:FileList1','read')
  106.    line1=readln('in1')
  107.    errdir=dir1
  108.    if EOF('in1') then signal error10
  109.    call close('in1')
  110.    call open('in2','T:FileList2','read')
  111.    line2=readln('in2')
  112.    errdir=dir2
  113.    if EOF('in2') then signal error10
  114.    call close('in2')
  115.    'Sort T:FileList1 To T:FileList1 Case ColStart 10'
  116.    'Sort T:FileList2 To T:FileList2 Case ColStart 10'
  117.    end
  118. call open('in1','T:FileList1','read')
  119. call open('in2','T:FileList2','read')
  120. do forever
  121.    line1=readln('in1')
  122.    if line1='' then leave
  123.    len1=left(line1,8)
  124.    call seek('in2',0,'B')
  125.    do forever
  126.       line2=readln('in2')
  127.       if line2='' then leave
  128.       len2=left(line2,8)
  129.       if len1=len2 then do
  130.          fname1=right(line1,length(line1)-9)
  131.          fname2=right(line2,length(line2)-9)
  132.          select
  133.             when abbrev(dir1,dir2) & abbrev(fname2,dir1) then ineq=fname1<fname2
  134.             when abbrev(dir2,dir1) & abbrev(fname1,dir2) then ineq=fname1<fname2
  135.             when dir1=dir2 then ineq=fname1<fname2
  136.             otherwise ineq=1
  137.             end
  138.          if ineq then do
  139.             if exists(fname2)=1 then do
  140.                cmp '"'fname1'" "'fname2'" DUMP 0 CHECKD >NIL:'
  141.                if RC=0 then do
  142.                   str1=delstr(fname1,1,length(dir1))
  143.                   str2=delstr(fname2,1,length(dir2))
  144.                   say ''str1'  ==  'str2
  145.                   flag=1
  146.                   if opt1='DELETE' | opt2='DELETE' then do
  147.                      'Echo "   " NoLine'
  148.                      'Delete "'fname2'" Force'
  149.                      say 'A'
  150.                      end
  151.                   end
  152.                end
  153.             end
  154.          end
  155.       end
  156.    end
  157. call close('in2')
  158. call close('in1')
  159. 'Delete T:FileList1 T:FileList2 Quiet'
  160. if flag~=1 then say 'No equal files detected.'
  161. exit
  162.  
  163.  
  164. error1:
  165. say 'BImproper number of " delimiters!B'
  166. exit
  167.  
  168.  
  169. error2:
  170. say 'BIllegal input string!B'
  171. signal template
  172. exit
  173.  
  174.  
  175. error3:
  176. say 'BPlease do not use ":" and "/" abbreviations!B'
  177. exit
  178.  
  179.  
  180. error4:
  181. say 'B<dir1> "'dir1'" does not exist!B'
  182. exit
  183.  
  184.  
  185. error5:
  186. say 'B<dir1> "'dir1'" must be a directory!B'
  187. exit
  188.  
  189.  
  190. error6:
  191. say 'B<dir2> "'dir2'" does not exist!B'
  192. exit
  193.  
  194.  
  195. error7:
  196. say 'B<dir2> "'dir2'" must be a directory!B'
  197. exit
  198.  
  199.  
  200. error8:
  201. say 'BOption 'opt1' not allowed!B'
  202. exit
  203.  
  204.  
  205. error9:
  206. say 'BOption 'opt2' not allowed!B'
  207. exit
  208.  
  209.  
  210. error10:
  211. say 'BNo files in directory "'errdir'" !B'
  212. exit
  213.  
  214.  
  215. template:
  216. say 'BEqFiles V1.8 by Fulvio Peruggi - October 11, 1998B'
  217. say 'Usage: [rx] EqFiles[.rexx] [<dir1>] [<dir2>] [ALL] [DELETE]'
  218. say 'BScans all files in directories <dir1> and <dir2>, compares all pairs of'
  219. say '  files having the same size, and lists all pairs of equal files.'
  220. say 'Scans, compares, and lists all pairs of equal files in <dir1>, if'
  221. say '  <dir2>=<dir1> or if <dir2> is not specified.'
  222. say 'Command operations act on all subdirectories and their files if the'
  223. say '  optional parameter ALL is specified.'
  224. say 'Equal files found in <dir2> are deleted if the optional parameter DELETE'
  225. say '  is specified.B'
  226. exit
  227.